import Vue from 'vue'
import Router from 'vue-router'
import Abstract from '../components/abstruct.vue'
Vue.use(Router)

let baseRoute = [{
  path: '/canteen',
  name: '食堂设置',
  component: Abstract,
  children: [{
    path: 'base',
    name: '基础设置',
    component: (resolve) => require(['../views/canteen/base'], resolve)
  }, {
    path: 'can',
    name: '食堂',
    component: (resolve) => require(['../views/canteen/canteen'], resolve)
  }, {
    path: 'periods',
    name: '餐别',
    component: (resolve) => require(['../views/canteen/periods'], resolve)
  }, {
    path: 'chef',
    name: '厨师',
    component: (resolve) => require(['../views/canteen/chef'], resolve)
  }, {
    path: 'item',
    name: '单品类别',
    component: (resolve) => require(['../views/canteen/item'], resolve)
  }, {
    path: 'tableware',
    name: '餐具',
    component: (resolve) => require(['../views/canteen/tableware'], resolve)
  }, {
    path: 'discount',
    name: '卡优惠规则',
    component: (resolve) => require(['../views/canteen/discount'], resolve)
  }]
}, {
  path: '/card',
  name: '卡务设置',
  component: Abstract,
  children: [{
    path: 'base',
    name: '卡务基础设置',
    component: (resolve) => require(['../views/card/base'], resolve)
  }, {
    path: 'center',
    name: '卡务中心',
    component: (resolve) => require(['../views/card/center'], resolve)
  }, {
    path: 'type',
    name: '卡类型',
    component: (resolve) => require(['../views/card/type'], resolve)
  }, {
    path: 'user',
    name: '持卡人类别',
    component: (resolve) => require(['../views/card/user'], resolve)
  }, {
    path: 'rules',
    name: '按次消费规则',
    component: (resolve) => require(['../views/card/rules'], resolve)
  }]
}, {
  path: '/manager',
  name: '卡管理 ',
  component: Abstract,
  children: [{
    path: 'open',
    name: '开卡',
    component: (resolve) => require(['../views/cardManager/open'], resolve)
  }, {
    path: 'manager',
    name: '卡管理',
    component: (resolve) => require(['../views/cardManager/manager'], resolve)
  }, {
    path: 'list',
    name: '卡列表',
    component: (resolve) => require(['../views/cardManager/list'], resolve)
  }]
}, {
  path: '/windows',
  name: '档口管理',
  component: Abstract,
  children: [{
    path: 'window',
    name: '档口',
    component: (resolve) => require(['../views/windows/window'], resolve)
  }, {
    path: 'item',
    name: '单品',
    component: (resolve) => require(['../views/windows/item'], resolve)
  }, {
    path: 'plan',
    name: '菜谱计划',
    component: (resolve) => require(['../views/windows/plan'], resolve)
  }]
}, {
  path: '/account',
  name: '餐卡账户',
  component: Abstract,
  children: [{
    path: 'rinsert',
    name: '批量充值导入',
    component: (resolve) => require(['../views/account/rinsert'], resolve)
  }, {
    path: 'rlogs',
    name: '批量充值日志',
    component: (resolve) => require(['../views/account/rlogs'], resolve)
  }, {
    path: 'sinsert',
    name: '批量补贴导入',
    component: (resolve) => require(['../views/account/sinsert'], resolve)
  }, {
    path: 'slogs',
    name: '批量补贴日志',
    component: (resolve) => require(['../views/account/slogs'], resolve)
  }]
}, {
  path: '/staff',
  name: '员工管理 ',
  component: Abstract,
  children: [{
    path: 'manager',
    name: '员工管理',
    component: (resolve) => require(['../views/staff/manager'], resolve)
  }]
}, {
  path: '/kitchen',
  name: '后厨出票 ',
  component: Abstract,
  children: [{
    path: 'kitchen',
    name: '后厨出票',
    component: (resolve) => require(['../views/kitchen/kitchen'], resolve)
  }]
}]

let router = new Router({
  routes: baseRoute,
  mode: 'history'
})
// 路由守卫
router.beforeEach((to, from, next) => {
  let routeName = to.meta.name || to.name
  window.document.title = routeName
  next()
})
export default router
